package ua.org.extjsbuilder.parser.runtime;

import ua.org.extjsbuilder.parser.IInstruction;
import ua.org.extjsbuilder.parser.runtime.data.JSFunction;
import ua.org.extjsbuilder.parser.runtime.instructions.Breaker;

public class KeywordsInterpreterTestCase extends AbstractInterpreterTestCase {
	
	public void testKeywords() throws Exception{
		JSFunction fn = (JSFunction)parseFile("func.js",JSFunction.class).get(0);
		IInstruction bc = fn.getBody().get(0);
		assertEquals(Breaker.class, bc.getClass());
		Breaker breaker = (Breaker)bc;
		assertEquals(breaker.getName(),Breaker.RETURN);
		//TODO: check for expression
		
		bc = parseString("break",Breaker.class).get(0);
		assertEquals(Breaker.class, bc.getClass());
		breaker = (Breaker)bc;
		assertEquals(breaker.getName(),Breaker.BREAK);
		
		bc = parseString("break mark;",Breaker.class).get(0);
		assertEquals(Breaker.class, bc.getClass());
		breaker = (Breaker)bc;
		assertEquals(breaker.getName(),Breaker.BREAK);
		
		bc = parseString("continue",Breaker.class).get(0);
		assertEquals(Breaker.class, bc.getClass());
		breaker = (Breaker)bc;
		assertEquals(breaker.getName(),Breaker.CONTINUE);
		
		bc = parseString("continue mark;",Breaker.class).get(0);
		assertEquals(Breaker.class, bc.getClass());
		breaker = (Breaker)bc;
		assertEquals(breaker.getName(),Breaker.CONTINUE);
	}

	@Override
	protected String getMockPkg() {
		return "ua/org/extjsbuilder/parser/runtime/keywords/";
	}
	
}
